package snmptest.gateway;

import java.util.Iterator;

import com.isnmp.common.snmp.SNMPFactory;
import com.isnmp.common.snmp.trap.TrapMessageInfo;
import com.isnmp.common.snmp.trap.TrapReceiverServer;

public class TrapRecieverTest {
    public static void main(String[] args) {
        try {
            SNMPFactory.init(1, "", 0);
            Iterator localIterator;
            for (;; localIterator.hasNext()) {
                TrapMessageInfo trap = TrapReceiverServer.getTrap();
                System.out.println("\n\n收到一个TRAP!!");
                System.out.println("发送Trap的设备IP: " + trap.getAgentSendIP());
                System.out.println("TRAP中指明的设备IP: " + trap.getPduAgentIP());
                System.out.println("TRAP版本（1-V1,2-V2）: " + trap.getTrapVersion());
                System.out.println("解析出的TRAP名称: " + trap.getTrapName());
                System.out.println("TRAP接收时间: " + trap.getReceiverTime());
                System.out.println("TRAP的OID（V2）或EnterpriseOID（V1）: " + trap.getTrapOID());
                if (trap.getTrapVersion() == 1) {
                    System.out.println("TRAP V1版本中标准Trap类型（0-5标准类型，6-私有类型）: " + trap.getTrapV1GenericType());
                    if (trap.getTrapV1GenericType() == 6) {
                        System.out.println("TRAP V1版本中私有Trap类型: " + trap.getTrapV1SpecificType());
                    }
                }
                System.out.println("Trap中绑定的OID和OID值如下：");
                localIterator = trap.getTrapPDUOIDs().iterator();
                //continue;
                String oid = (String) localIterator.next();

                System.out.println("OID: " + oid + " , 值: " + trap.getOIDValue(oid));
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}